<?php

namespace App\Console\Commands;

use App\Models\Behavior;
use App\Models\Child;

use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Illuminate\Support\Facades\Log;

class MakeBehaviorData extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    //protected $signature = 'command:name';
    protected $signature = 'db:makebehavior';
    /**
     * The console command description.
     *
     * @var string
     */
    //protected $description = 'Command description';
    protected $description = 'db make behavior data';

    protected $process;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $agency_id = 1;

        $children = Child::where("id", "<", 10000)->get();


        $children->each(function (&$item) {
            $types = ['face', 'hand', 'eye'];
            foreach ($types as $type) {

                $score = rand(8, 12);

                for ($i = 1; $i < 41; $i++) {
                    if ($i <= 9) {
                        //基线期，稳定
                        $score += rand(-4, 4);

                    } else if ($i > 9 and $i < 27) {
                        //干预期，增长
                        $score += rand(-2, 3);

                    } else {
                        //基线期，稳定
                        $score += rand(-5, 5);
                    }

                    $data = ['child_id' => $item->id,
                        'name' => $type,
                        'score' => $score,
                        'test_date' => $i,
                    ];

                    Behavior::create($data);
                }
            }


        });

    }
}
